package com.chenglu.android.supermarket.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.utils.BigDecimalUtil;
import com.chenglu.android.common.utils.GlideUtils;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.index.bean.IndexRecomBean;
import com.chenglu.android.mine.bean.CollectBean;
import com.chenglu.android.mine.collect.adapter.CouponListAdapter;

import java.util.List;

/**
 * @author: lyj
 * @Created: by Copyright 2023/7/24 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：
 */
public class SellGoodsAdapter extends BaseQuickAdapter<IndexRecomBean.Data.Records, BaseViewHolder> {

    private Context mContext;

//    private final ViewBinderHelper viewBinderHelper = new ViewBinderHelper();

    public SellGoodsAdapter(Context context, @Nullable List<IndexRecomBean.Data.Records> data) {
        super(R.layout.item_sell_goods, data);
        this.mContext = context;

    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, IndexRecomBean.Data.Records item) {

        if (item == null) {
            return;
        }
        ImageView imageView = helper.getView(R.id.iv_shop_pic);
        Glide.with(mContext).load(item.getGoodsImg()).into(imageView);
        helper.setText(R.id.tv_price,Utils.formatZeroNumber(item.getGoodsPrice()));
        if(item.getDiscount().equals("0.0")){
            helper.setGone(R.id.tv_market_price,false);
        }else {
            helper.setGone(R.id.tv_market_price,false);
            //打折商品的计算
            String div = BigDecimalUtil.div(item.getDiscount(), "10", 2);
            String discountPrice = BigDecimalUtil.mul(item.getGoodsPrice(), div);
            TextView textView = helper.getView(R.id.tv_market_price);
            textView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            textView.setText("¥"+Utils.formatZeroNumber(discountPrice));


        }


    }

}
